<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {

	protected $table = 'Admin';
	
	/**
	 * 登录
	 */
    public function index(){
		if(!empty($_SESSION['admin'])) { // 验证是否登录
			redirect(U('Class/index'), 0, '');
		}
		if(IS_POST) {
			$admin = D($this->table);
			$checkmsg = $admin->checkform($_POST);
			if(!empty($checkmsg)) { // 表单验证
				$this->error($checkmsg);
			} else { // 表单处理
				$info = $admin->login();
				if(empty($info)) {
					$this->error('登录失败！');
				} else {
					$_SESSION['admin'] = $info;
					$this->error('登录成功！',U('Class/index'));
				}
			}
		}
		$this->display();
    }
	
	/**
	 * 退出
	 */
	public function out() {
		unset($_SESSION['admin']);
		$this->success('退出成功！', U('Admin/Login/index'));
	}
}
